home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / util / gnu / cvs-1.11.1p1.lha / contrib / cvs2vendor < prev    next >
Encoding:
Text File  |  2001-05-01  |  4.4 KB  |  143 lines

  1. #! /bin/sh
  2. #
  3. #    cvs2vendor - move revsisions from files in A to files in B
  4. # The primary reason for this script is to move deltas from a
  5. # non-vendor branched repository onto a fresh vendor branched one,
  6. # skipping the initial checkin in assumption that it is the same in
  7. # both repositories.  This way you can take a project that was moved
  8. # into CVS without the benefit of the vendor branch and for all
  9. # intents and purposes add the vendor branch underneath the existing
  10. # deltas.
  11. # This script is also a decent example of repository maintenance using
  12. # raw RCS commands (if I do say so myself! ;-).
  13. # Tags are preserved.
  14. # The timestamp of the initial vendor branch revision will be adjusted
  15. # to be the same as the 1.1 revision of each source file.
  16. # Extra branches in the source directory will cause breakage.
  17. # Intermediate files are created in the current working directory
  18. # where this script is started.
  19. # Written by Greg A. Woods <woods@planix.com>, based on rcs2sccs
  20. # (retains some of the rlog parsing from it).
  21. # The copyright is in the Public Domain.
  22. #
  23.  
  24. if [ $# -ne 2 ]; then
  25.     echo USAGE: $0 srcdir dstdir
  26.     exit 2
  27. fi
  28. tsrcdir=$1
  29. tdstdir=$2
  30.  
  31. revfile=/tmp/cvs2vendor_$$_rev
  32. rm -f $revfile
  33.  
  34. commentfile=/tmp/cvs2vendor_$$_comment
  35. rm -f $commentfile
  36.  
  37. srcdirs=`cd $tsrcdir && find . -type d -print | sed 's~^\.[/]*~~'`
  38.  
  39. # the "" is a trick to get $tsrcdir itself without resorting to '.'
  40. for ldir in "" $srcdirs; do
  41.  
  42.     srcdir=$tsrcdir/$ldir
  43.     dstdir=$tdstdir/$ldir
  44.  
  45.     # Loop over every RCS file in srcdir
  46.     #
  47.     for vfile in $srcdir/*,v; do
  48.         # get rid of the ",v" at the end of the name
  49.         file=`echo $vfile | sed -e 's/,v$//'`
  50.         bfile=`basename $file`
  51.  
  52.         if [ ! -d $dstdir ]; then
  53.             echo "making locally added directory $dstdir"
  54.             mkdir -p $dstdir
  55.         fi
  56.         if [ ! -f $dstdir/$bfile,v ]; then
  57.             echo "copying locally added file $dstdir/$bfile ..."
  58.             cp $vfile $dstdir
  59.             continue;
  60.         fi
  61.  
  62.         # work on each rev of that file in ascending order
  63.         rlog $file | grep "^revision [0-9][0-9]*\." | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u +0 +1 +2 +3 +4 +5 +6 +7 +8 | sed -e 's/ /./g' > $revfile
  64.  
  65.         for rev in `cat $revfile`; do
  66.  
  67.             case "$rev" in
  68.             1.1)
  69.                 newdate=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s.%s\n",$2,$3); exit}' | sed -e 's~/~.~g' -e 's/:/./g' -e 's/;//' -e 's/^19//'`
  70.                 olddate=`rlog -r1.1.1.1 $dstdir/$bfile | grep "^date: " | awk '{printf("%s.%s\n",$2,$3); exit}' | sed -e 's~/~.~g' -e 's/:/./g' -e 's/;//' -e 's/^19//'`
  71.                 sed "s/$olddate/$newdate/" < $dstdir/$bfile,v > $dstdir/$bfile.x
  72.                 mv -f $dstdir/$bfile.x $dstdir/$bfile,v
  73.                 chmod -w $dstdir/$bfile,v
  74.                 symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[     ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s:1.1.1.1\n",$1)}'`
  75.                 if [ -n "$symname" ]; then
  76.                     echo "tagging $file with $symname ..."
  77.                     rcs $symname $dstdir/$bfile,v
  78.                     if [ $? != 0 ]; then
  79.                         echo ERROR - rcs $symname $dstdir/$bfile,v
  80.                         exit 1
  81.                     fi
  82.                 fi
  83.                 continue            # skip first rev....
  84.                 ;;
  85.             esac
  86.  
  87.             # get a lock on the destination local branch tip revision
  88.             co -r1 -l $dstdir/$bfile
  89.             if [ $? != 0 ]; then
  90.                 echo ERROR - co -r1 -l $dstdir/$bfile
  91.                 exit 1
  92.             fi
  93.             rm -f $dstdir/$bfile
  94.  
  95.             # get file into current dir and get stats
  96.             date=`rlog -r$rev $file | grep "^date: " | awk '{printf("%s %s\n",$2,$3); exit}' | sed -e 's/;//'`
  97.             author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
  98.  
  99.             symname=`rlog -h $file | sed -e '1,/^symbolic names:/d' -e 's/[     ]*//g' | awk -F: '$2 == "'"$rev"'" {printf("-n%s\n",$1)}'`
  100.  
  101.             rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
  102.  
  103.             echo "==> file $file, rev=$rev, date=$date, author=$author $symname"
  104.  
  105.             co -p -r$rev $file > $bfile
  106.             if [ $? != 0 ]; then
  107.                 echo ERROR - co -p -r$rev $file
  108.                 exit 1
  109.             fi
  110.  
  111.             # check file into vendor repository...
  112.             ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
  113.             if [ $? != 0 ]; then
  114.                 echo ERROR - ci -f -m"`cat $commentfile`" -d"$date" $symname -w"$author" $bfile $dstdir/$bfile,v
  115.                 exit 1
  116.             fi
  117.             rm -f $bfile
  118.  
  119.             # set the default branch to the trunk...
  120.             # XXX really only need to do this once....
  121.             rcs -b1 $dstdir/$bfile
  122.             if [ $? != 0 ]; then
  123.                 echo ERROR - rcs -b1 $dstdir/$bfile
  124.                 exit 1
  125.             fi
  126.         done
  127.     done
  128. done
  129.  
  130. echo cleaning up...
  131. rm -f $commentfile
  132. echo "       Conversion Completed Successfully"
  133.  
  134. exit 0
  135.